package de.hwrberlin.remo.diagram.providers;

import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.gmf.runtime.common.core.service.AbstractProvider;
import org.eclipse.gmf.runtime.common.core.service.IOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.GetParserOperation;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.IParserProvider;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserService;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.emf.ui.services.parser.ParserHintAdapter;
import org.eclipse.gmf.runtime.notation.View;

import de.hwrberlin.remo.diagram.edit.parts.AndRuleNameEditPart;
import de.hwrberlin.remo.diagram.edit.parts.BooleanFactNameEditPart;
import de.hwrberlin.remo.diagram.edit.parts.ImplicationNameEditPart;
import de.hwrberlin.remo.diagram.edit.parts.LinksFromFactsLinknameEditPart;
import de.hwrberlin.remo.diagram.edit.parts.LinksFromRulesLinknameEditPart;
import de.hwrberlin.remo.diagram.edit.parts.OrRuleNameEditPart;
import de.hwrberlin.remo.diagram.parsers.MessageFormatParser;
import de.hwrberlin.remo.diagram.part.RemoVisualIDRegistry;
import de.hwrberlin.remo.model.RemoModelPackage;

/**
 * @generated
 */
public class RemoParserProvider extends AbstractProvider implements
		IParserProvider {

	/**
	 * @generated
	 */
	private IParser andRuleName_5004Parser;

	/**
	 * @generated
	 */
	private IParser getAndRuleName_5004Parser() {
		if (andRuleName_5004Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getRemoObject_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			andRuleName_5004Parser = parser;
		}
		return andRuleName_5004Parser;
	}

	/**
	 * @generated
	 */
	private IParser implicationName_5007Parser;

	/**
	 * @generated
	 */
	private IParser getImplicationName_5007Parser() {
		if (implicationName_5007Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getRemoObject_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			implicationName_5007Parser = parser;
		}
		return implicationName_5007Parser;
	}

	/**
	 * @generated
	 */
	private IParser booleanFactName_5005Parser;

	/**
	 * @generated
	 */
	private IParser getBooleanFactName_5005Parser() {
		if (booleanFactName_5005Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getRemoObject_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			booleanFactName_5005Parser = parser;
		}
		return booleanFactName_5005Parser;
	}

	/**
	 * @generated
	 */
	private IParser orRuleName_5006Parser;

	/**
	 * @generated
	 */
	private IParser getOrRuleName_5006Parser() {
		if (orRuleName_5006Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getRemoObject_Name() };
			MessageFormatParser parser = new MessageFormatParser(features);
			orRuleName_5006Parser = parser;
		}
		return orRuleName_5006Parser;
	}

	/**
	 * @generated
	 */
	private IParser linksFromRulesLinkname_6003Parser;

	/**
	 * @generated
	 */
	private IParser getLinksFromRulesLinkname_6003Parser() {
		if (linksFromRulesLinkname_6003Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getLinkObject_Linkname() };
			MessageFormatParser parser = new MessageFormatParser(features);
			linksFromRulesLinkname_6003Parser = parser;
		}
		return linksFromRulesLinkname_6003Parser;
	}

	/**
	 * @generated
	 */
	private IParser linksFromFactsLinkname_6004Parser;

	/**
	 * @generated
	 */
	private IParser getLinksFromFactsLinkname_6004Parser() {
		if (linksFromFactsLinkname_6004Parser == null) {
			EAttribute[] features = new EAttribute[] { RemoModelPackage.eINSTANCE
					.getLinkObject_Linkname() };
			MessageFormatParser parser = new MessageFormatParser(features);
			linksFromFactsLinkname_6004Parser = parser;
		}
		return linksFromFactsLinkname_6004Parser;
	}

	/**
	 * @generated
	 */
	protected IParser getParser(int visualID) {
		switch (visualID) {
		case BooleanFactNameEditPart.VISUAL_ID:
			return getBooleanFactName_5005Parser();
		case AndRuleNameEditPart.VISUAL_ID:
			return getAndRuleName_5004Parser();
		case ImplicationNameEditPart.VISUAL_ID:
			return getImplicationName_5007Parser();
		case OrRuleNameEditPart.VISUAL_ID:
			return getOrRuleName_5006Parser();
		case LinksFromRulesLinknameEditPart.VISUAL_ID:
			return getLinksFromRulesLinkname_6003Parser();
		case LinksFromFactsLinknameEditPart.VISUAL_ID:
			return getLinksFromFactsLinkname_6004Parser();
		}
		return null;
	}

	/**
	 * Utility method that consults ParserService
	 * @generated
	 */
	public static IParser getParser(IElementType type, EObject object,
			String parserHint) {
		return ParserService.getInstance().getParser(
				new HintAdapter(type, object, parserHint));
	}

	/**
	 * @generated
	 */
	public IParser getParser(IAdaptable hint) {
		String vid = (String) hint.getAdapter(String.class);
		if (vid != null) {
			return getParser(RemoVisualIDRegistry.getVisualID(vid));
		}
		View view = (View) hint.getAdapter(View.class);
		if (view != null) {
			return getParser(RemoVisualIDRegistry.getVisualID(view));
		}
		return null;
	}

	/**
	 * @generated
	 */
	public boolean provides(IOperation operation) {
		if (operation instanceof GetParserOperation) {
			IAdaptable hint = ((GetParserOperation) operation).getHint();
			if (RemoElementTypes.getElement(hint) == null) {
				return false;
			}
			return getParser(hint) != null;
		}
		return false;
	}

	/**
	 * @generated
	 */
	private static class HintAdapter extends ParserHintAdapter {

		/**
		 * @generated
		 */
		private final IElementType elementType;

		/**
		 * @generated
		 */
		public HintAdapter(IElementType type, EObject object, String parserHint) {
			super(object, parserHint);
			assert type != null;
			elementType = type;
		}

		/**
		 * @generated
		 */
		@SuppressWarnings("rawtypes")
		public Object getAdapter(Class adapter) {
			if (IElementType.class.equals(adapter)) {
				return elementType;
			}
			return super.getAdapter(adapter);
		}
	}

}
